<template>
  <div class="orders">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryinfo.query" clearable @clear="getOrders()">
            <el-button slot="append" icon="el-icon-search" @click="getOrders()"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="tableData" style="width: 100%" stripe border>
        <el-table-column label="#" type="index" width="40"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="140"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款" width="140">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay == '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="140"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="200">
          <template slot-scope="scope">{{scope.row.create_time | timefilter}}</template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template>
            <el-button type="primary" icon="el-icon-edit" @click="xiugaiAddress"></el-button>
            <el-button type="success" icon="el-icon-setting" @click="ViewLogistics"></el-button>            
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>

<el-dialog
  title="修改地址"
  :visible.sync="addressVisible"
  width="60%"
  @close="addressClose"
>
<el-form :model="ruleForm" :rules="rules" ref="ruleFormRef" label-width="100px">
  <el-form-item label="省市区/县" prop="address1">
<el-cascader
    v-model="ruleForm.address1"
    :options="cityData"
    :props="{ expandTrigger: 'hover' }"
    style="width:100%"
 ></el-cascader>

  </el-form-item>
  <el-form-item label="详细地址" prop="address2">
    <el-input v-model="ruleForm.address2"></el-input>
  </el-form-item>  
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="addressVisible = false">取 消</el-button>
    <el-button type="primary" @click="addressVisible = false">确 定</el-button>
  </span>
</el-dialog>

<el-dialog
  title="查看物流"
  :visible.sync="logisticsVisible"
  width="60%"
>
  <el-timeline>
    <el-timeline-item
      v-for="(activity, index) in activities"
      :key="index"
      :timestamp="activity.ftime">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
</el-dialog>
  </div>
</template>

<script>
import cityData from './city_data.js'
export default {
  name: "orders",
  data() {
    return {
      tableData: [],
      queryinfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
        user_id: "",
        pay_status: "",
        is_send: "",
        order_fapiao_title: "",
        order_fapiao_company: "",
        order_fapiao_content: "",
        consignee_addr: "",
      },
      total: null,
      addressVisible:false,
      ruleForm:{
        address1:[],
        address2:""

      },
      rules:{
        address1:[
          { required: true, message: '请输入省市区/县', trigger: 'blur' },         
        ],
       address2:[
          { required: true, message: '请输入详细地址', trigger: 'blur' },         
        ],
      },
      cityData,
      logisticsVisible:false,
      activities: []
    };
  },
  methods: {
    getOrders() {
      this.$http.get("orders", { params: this.queryinfo }).then((res) => {
        if (res.data.meta.status !== 200) {
          return this.$message.error("数据加载失败");
        }
        this.tableData = res.data.data.goods;
        this.total = res.data.data.total;
      });
    },
    handleSizeChange(index) {
      this.queryinfo.pagesize = index;
      this.getOrders();
    },
    handleCurrentChange(index) {
      this.queryinfo.pagenum = index;
      this.getOrders();
    },
    xiugaiAddress() {
      this.addressVisible = true;

    },
    addressClose() {
      this.$refs.ruleFormRef.resetFields();
    },
    ViewLogistics() {
      this.$http.get('kuaidi/1106975712662').then( res => {
        if(res.data.meta.status !== 200){
          return this.$message.error("获取数据失败");
        }
        this.activities = res.data.data;
        this.logisticsVisible = true;
      })
      

    }
  },
  mounted() {
    this.getOrders();
  },
};
</script>

<style scoped>
.el-breadcrumb {
  margin-bottom: 20px;
}
.el-row {
  margin-bottom: 10px;
}
.el-pagination{
  margin-top:15px;
}
</style>
